package crp.services.api.graphql;

import crp.core.analysis.app.ViewFlowService;
import crp.core.security.Callers;
import crp.services.api.graphql.models.CreateViewFlowInput;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Mutation;

import javax.annotation.security.PermitAll;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@GraphQLApi
@RequestScoped
public class AnalysisGraphQLApi {
    private final ViewFlowService viewFlowService;

    @Inject
    public AnalysisGraphQLApi(ViewFlowService viewFlowService) {
        this.viewFlowService = viewFlowService;
    }

    @Mutation
    @PermitAll
    @NotNull
    public boolean createViewFlow(@NotNull @Valid CreateViewFlowInput input) {
        viewFlowService.creator().create(input.createCommand(Callers.current()));
        return true;
    }
}
